package com.imooc.newretail.smartcabinet.service.impl;

import com.imooc.newretail.smartcabinet.entity.IotSmartCabinet;
import com.imooc.newretail.smartcabinet.enums.DeviceStatusEnum;
import com.imooc.newretail.smartcabinet.mapper.IotSmartCabinetMapper;
import com.imooc.newretail.smartcabinet.service.IIotSmartCabinetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 智能柜信息表 服务实现类
 * </p>
 *
 * @author Hank
 * @since 2020-07-01
 */
@Service
public class IotSmartCabinetServiceImpl extends ServiceImpl<IotSmartCabinetMapper, IotSmartCabinet> implements IIotSmartCabinetService {

    /***
     * 激活设备
     * @param deviceId 设备ID
     * @param token 验证密匙
     * @return
     */
    @Override
    public boolean activate(String deviceId, String token) {
        // 验证Token的有效性
        IotSmartCabinet smartCabinet = baseMapper.selectById(deviceId);
        smartCabinet.setState(DeviceStatusEnum.ENABLE.getCode());
        return baseMapper.updateById(smartCabinet) > 0 ? true : false;
    }
}
